package com.duobaoyu.dby.supply.admin.controller.config;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.common.core.validator.groups.Add;
import com.duobaoyu.dby.common.core.validator.groups.Edit;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceChannelConfigAdminClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.ChannelConfigBizDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.ChannelConfigVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * 渠道配置
 *
 * @Author tianxiaoqiang
 * @Date 2022/6/22 15:17
 * @Version 1.0
 * @Description 渠道配置表
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/channel-config")
@Api(value = "channel-config", tags = "渠道配置表")
public class ChannelConfigController {

	private final ResourceChannelConfigAdminClient resourceChannelConfigAdminClient;

	/**
	 * 添加渠道配置信息
	 *
	 * @param channelConfigBiz
	 * @return boolean
	 */
	@PostMapping("/create")
	@ApiOperation(value = "添加渠道配置", notes = "添加渠道配置信息")
	@SupplySysLog(value = "添加渠道配置信息",operationType = OperationTypeEnum.INTERT)
	public R<Boolean> add(@RequestBody @Validated(Add.class) ChannelConfigBizDTO channelConfigBiz) {
		return R.ok(resourceChannelConfigAdminClient.addChannelConfig(channelConfigBiz));
	}

	/**
	 * 修改渠道配置
	 *
	 * @param channelConfigBiz
	 * @return boolean
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改渠道配置", notes = "修改渠道配置信息")
	@SupplySysLog(value = "修改渠道配置信息",operationType = OperationTypeEnum.UPDATE)
	public R<Boolean> update(@RequestBody @Validated(Edit.class) ChannelConfigBizDTO channelConfigBiz) {

		return R.ok(resourceChannelConfigAdminClient.updateChannelConfig(channelConfigBiz));
	}

	/**
	 * 删除渠道配置
	 *
	 * @param id
	 * @return boolean
	 */
	@DeleteMapping("/delete/{id}")
	@ApiOperation(value = "删除渠道配置", notes = "删除渠道配置信息")
	@SupplySysLog(value = "删除渠道配置信息",operationType = OperationTypeEnum.DELETE)
	public R<Boolean> delete(@NotNull(message = "渠道配置信息ID不能为空") @PathVariable("id") Long id) {

		return R.ok(resourceChannelConfigAdminClient.removeChannelConfig(id));
	}

	/**
	 * 查询渠道配置信息详情
	 *
	 * @param id
	 * @return
	 */
	@GetMapping("/{id}")
	@ApiOperation(value = "查询渠道配置信息详情", notes = "根据id查询渠道配置信息详情")
	@SupplySysLog(value = "根据id查询渠道配置信息详情",operationType = OperationTypeEnum.SELECT)
	public R<ChannelConfigVO> queryOne(@NotNull(message = "渠道配置信息ID不能为空") @PathVariable("id") Long id) {

		return R.ok(resourceChannelConfigAdminClient.getById(id));
	}

	/**
	 * 分页查询渠道配置信息
	 *
	 * @param channelConfigBiz
	 * @return
	 */
	@PostMapping("/page")
	@ApiOperation(value = "分页查询渠道配置信息", notes = "分页查询渠道配置信息")
	@SupplySysLog(value = "分页查询渠道配置信息",operationType = OperationTypeEnum.SELECT)
	public R<Page<ChannelConfigVO>> page(@RequestBody ChannelConfigBizDTO channelConfigBiz) {

		return R.ok(resourceChannelConfigAdminClient.page(channelConfigBiz));
	}
}
